<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<head>
<style type="text/css">
h1 span{visibility:visible;}
td span{visibility:visible;}
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
</head>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="frontHostname" value='<%=ServerValue.getFrontHostname() %>'/>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script language="javascript">
	$().ready( function() {

		if('${error}'!=''){
			var err = "${error}".split(',');
			for(var i=1; i<=err.length; i++){
				$("#tab" + err[i-1] + "Tip").text("商品编号不正确");
				$("#tab" + err[i-1] + "Tip").show();
				$("#tab" + err[i-1] + "ProdId").focus();
			}
		}

		$(":input[name*='ProdId']").each(function(){
			$("#" + this.id).numeric();
			$(this).blur(function(){
				$(this).val(prodPadLeft($(this).val()));
				if(this.id == 'tab8ProdId')
					getProductInfo3("${midContextPath}",'tab8Name','tab8Brief','tab8ProdIsOk',$(this).val());
				else
					getProductInfo3("${midContextPath}",this.id.substring(0,4) + "Name",this.id.substring(0,4) + "Brief",this.id.substring(0,4) + "ProdIsOk",$(this).val());
			});
		});
		
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$("#subBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("10");
				$("#specialActAdvForm").submit();
			}
		});

		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#specialActAdvForm").submit();
			}
		});
		
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#specialActAdvForm").submit();
			}
		});
		
		$("#bannerImg").change(
			function(){
				checkImg(this, 70, 768, 180, $("#imageFileCorrect"), "");
			});
	});
	
	function validate_data(){
		var isCorrect = true;
		$("span:[id*=Tip]").hide();
		$("span:[id*=Tip]").text('');
		if ( $("#bannerImg").val() != "" )
			$("#bannerImgName").val($("#bannerImg").val());
		for( var i = 8; i >=1 ; i-- ){
			
			if ( $("#tab" + i + "ProdId").val() == "" ){
				appendWord($("#tab" + i + "Tip"),"请输入商品编号");
				$("#tab" + i + "Tip").show();
				$("#tab" + i + "ProdId").focus();
				isCorrect = false;
			}else if ( $("#tab" + i + "ProdIsOk").val() == "N" ){
				appendWord($("#tab" + i + "Tip"),"商品编号错误");
				$("#tab" + i + "Tip").show();
				$("#tab" + i + "ProdId").focus();
				isCorrect = false;
			}
			
			if ( $("#tab" + i + "Brief").val() == "" ){
				appendWord($("#tab" + i + "Tip"),"请输入显示小标");
				$("#tab" + i + "Tip").show();
				$("#tab" + i + "Brief").focus();
				isCorrect = false;
			}
			
			if ( $("#tab" + i + "Name").val() == "" ){
				appendWord($("#tab" + i + "Tip"),"请输入商品名称");
				$("#tab" + i + "Tip").show();
				$("#tab" + i + "Name").focus();
				isCorrect = false;
			}
		}
		if($("#bannerImgName").val() != ""){
			if ( $("#bannerImgLink").val() == "" ){
				$("#bannerImgLink").focus();
				$("#bannerImgTip").text("请输入图片点击连结");
				$("#bannerImgTip").show();
				isCorrect = false;
			}else if ( !isURL($("#bannerImgLink").val()) ){
				$("#bannerImgTip").text("图片点击连结格式错误");
				$("#bannerImgTip").show();
				$("#bannerImgLink").focus();
				isCorrect = false;
			}
			var imageFileErrorMessage = $("#imageFileCorrect").val();
			if (imageFileErrorMessage != '') {
				$("#bannerImgTip").text(imageFileErrorMessage);
				$("#bannerImgTip").show();
				isCorrect = false;
			}
		}
		if ( $("#showSeq").val() == "" ){
			$("#showSeqTip").text("请输入显示顺序");
			$("#showSeqTip").show();
			$("#showSeq").focus();
			isCorrect = false;
		}
		if ( $("#mainCateId").val() == "" ){
			$("#mainCateIdTip").text("请选馆别");
			$("#mainCateIdTip").show();
			$("#mainCateId").focus();
			isCorrect = false;
		}
		if($('#startDate').val()==''){
			$('#startDateTip').text('请输入起始日期');
			$('#startDateTip').show();
			$('#startDate').focus();
			isCorrect = false;
		}
		if($('#startTime').val()==''){
			$('#startTimeTip').text('请输入起始时间');
			$('#startTimeTip').show();
			$('#startTime').focus();
			isCorrect = false;
		}
		if($('#endDate').val()==''){
			$('#endDateTip').text('请输入结束日期');
			$('#endDateTip').show();
			$('#endDate').focus();
			isCorrect = false;
		}
		if($('#endTime').val()==''){
			$('#endTimeTip').text('请输入结束时间');
			$('#endTimeTip').show();
			$('#endTime').focus();
			isCorrect = false;
		}
		if($('#startDate').val()>$('#endDate').val()){
			$('#endDateTip').text('结束日期不能小于起始日期');
			$('#endDateTip').show();
			$('#startDate').focus();
			isCorrect = false;
		}else if($('#startDate').val()==$('#endDate').val()){
			if($('#startTime').val()>=$('#endTime').val()){
				$('#endTimeTip').text('结束时间需大于起始时间');
				$('#endTimeTip').show();
				$('#startDate').focus();
				isCorrect = false;
			}
		}
		if ( $("#advTitle").val() == "" ){
			$("#advTitleTip").text("请输入广告标题");
			$("#advTitleTip").show();
			$("#advTitle").focus();
			isCorrect = false;
		}
		if ( $("#advName").val() == "" ){
			$("#advNameTip").text("请输入广告名称");
			$("#advNameTip").show();
			$("#advName").focus();
			isCorrect = false;
		}
		
		return isCorrect;
	}

	function appendWord(origin, apptext){
		if(origin.text().length==0){
			origin.text(apptext);
		}else{
			origin.text(origin.text()+', '+apptext);
		}
		
	}
</script>
<h1>
	广告管理
	<br/>
	<div class="f-link">
		<a href="${midContextPath}/generate/cateMainProd/search.do">回广告查询页</a>
	</div>
</h1>
<s:if test="hasActionErrors()">
	<s:actionerror cssClass="msg rn" />
</s:if>
<s:if test="hasActionMessages()">
	<s:actionmessage cssClass="msg rn" />
</s:if>
<s:form action="specialAct/saveSpecialActAdv.do" method="post" name="specialActAdvForm" id="specialActAdvForm" enctype="multipart/form-data">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>类型</th>
				<td>活动特辑<input type="hidden" name="advType" id="advType" value="${advType}"/></td>
			</tr>
			<tr>
				<th>广告名称</th>
				<td><input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/><br/><span id="advNameTip" class="msg rn" style="display:none;"></span></td>
			</tr>
			<tr>
				<th>广告标题</th>
				<td><input type="text" id="advTitle" name="advTitle" value="${advTitle}" size="30"/><span class="txt-rd">建议15个字</span><br/><span id="advTitleTip" class="msg rn" style="display:none;"></span></td>
			</tr>
			<tr>
				<th>起迄时间</th>
				<td>
				<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/>
				<select id="startTime" name="startTime">			
						<c-rt:forEach begin="0" end="23" var="t1">
							<c-rt:if test="${t1<10}">
							<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<c-rt:if test="${t1>=10}">
							<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
						</c-rt:forEach>
				</select>  
				<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
				<select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
				</select>
				<span id="startDateTip" class="msg rn" style="display:none;"></span><span id="startTimeTip" class="msg rn" style="display:none;"></span><span id="endDateTip" class="msg rn" style="display:none;"></span><span id="endTimeTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>馆别</th>
				<td>
					<select id="mainCateId" name="mainCateId">
						<option value="">====== 请选择  ======</option>
						<c-rt:forEach items="${categoryRoot}" var="category">
							<option value="${category.id}" ${mainCateId eq category.id ? "selected" : ""}>${category.name}</option>
						</c-rt:forEach>
					</select>
					<span id="mainCateIdTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>显示顺序</th>
				<td>
					<select name="showSeq" id="showSeq">
						<c-rt:forEach begin="1" end="10" var="i">
							<option value="${i}" ${i eq showSeq ? 'selected' : ''}>${i}</option>
						</c-rt:forEach>
					</select>
					<span class="txt-rd">(排序条件: 是否有banner图, 显示顺序, 最后修改日期)</span>
				</td>
			</tr>
			<tr>
				<th colspan="4">tab设定</th>
			</tr>
			<tr>
				<th>大Banner</th>
				<td>
					<c-rt:if test="${not empty bannerImgName}">
						<img src="${frontHostname}/eventImg/${bannerImgFolder}/${advType}/${bannerImgName}" width="768" height="180"/><br/>
					</c-rt:if>
					<b>图片:</b><s:file id="bannerImg" name="bannerImg" value="" size="50" ></s:file><br/><span class="txt-rd">图片尺寸:768x180 &lt;70K</span>
					<s:hidden id="imageFileCorrect"></s:hidden>
					<s:if test="null != fieldErrors['bannerImg']">
					<br/>
					<p><span class="msg rn"><s:fielderror><s:param>bannerImg</s:param></s:fielderror></span></p>
					</s:if>
					<br/>
					<input type="hidden" id="bannerImgName" name="bannerImgName" value="${bannerImgName}"/>
					<input type="hidden" name="bannerImgFolder" value="${bannerImgFolder}"/>
					<b>图片点击连结:</b><input type="text" name="bannerImgLink" id="bannerImgLink" value="${bannerImgLink}" size="60"/><br/><span class="txt-rd">ex:http://www.yaodian100.com</span><br/>
					<span id="bannerImgTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>商品1</th>
				<td>
					<b>商品编号</b><input type="text" name="tab1ProdId" id="tab1ProdId" maxlength="8" size="10" value="${tab1ProdId}"/><br/>
					<input type="hidden" id="tab1ProdIsOk" value=""/>
					<b>显示小标:</b><input type="text" name="tab1Brief" id="tab1Brief" value="${tab1Brief}" maxlength="11" size="50"/><span class="txt-rd">11字內</span><br/>
					<b>商品名称:</b><input type="text" name="tab1Name" id="tab1Name" value="${tab1Name}" maxlength="22" size="50"/><span class="txt-rd">22字內</span><br/>
					<span id="tab1Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>商品2</th>
				<td>
					<b>商品编号</b><input type="text" name="tab2ProdId" id="tab2ProdId" maxlength="8" size="10" value="${tab2ProdId}"/><br/>
					<input type="hidden" id="tab2ProdIsOk" value=""/>
					<b>显示小标:</b><input type="text" name="tab2Brief" id="tab2Brief" value="${tab2Brief}" maxlength="11" size="50"/><span class="txt-rd">11字內</span><br/>
					<b>商品名称:</b><input type="text" name="tab2Name" id="tab2Name" value="${tab2Name}" maxlength="22" size="50"/><span class="txt-rd">22字內</span><br/>
					<span id="tab2Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>商品3</th>
				<td>
					<b>商品编号</b><input type="text" name="tab3ProdId" id="tab3ProdId" maxlength="8" size="10" value="${tab3ProdId}"/><br/>
					<input type="hidden" id="tab3ProdIsOk" value=""/>
					<b>显示小标:</b><input type="text" name="tab3Brief" id="tab3Brief" value="${tab3Brief}" maxlength="11" size="50"/><span class="txt-rd">11字內</span><br/>
					<b>商品名称:</b><input type="text" name="tab3Name" id="tab3Name" value="${tab3Name}" maxlength="22" size="50"/><span class="txt-rd">22字內</span><br/>
					<span id="tab3Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>	
			<tr>
				<th>商品4</th>
				<td>
					<b>商品编号</b><input type="text" name="tab4ProdId" id="tab4ProdId" maxlength="8" size="10" value="${tab4ProdId}"/><br/>
					<input type="hidden" id="tab4ProdIsOk" value=""/>
					<b>显示小标:</b><input type="text" name="tab4Brief" id="tab4Brief" value="${tab4Brief}" maxlength="11" size="50"/><span class="txt-rd">11字內</span><br/>
					<b>商品名称:</b><input type="text" name="tab4Name" id="tab4Name" value="${tab4Name}" maxlength="22" size="50"/><span class="txt-rd">22字內</span><br/>
					<span id="tab4Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>商品5</th>
				<td>
					<b>商品编号</b><input type="text" name="tab5ProdId" id="tab5ProdId" maxlength="8" size="10" value="${tab5ProdId}"/><br/>
					<input type="hidden" id="tab5ProdIsOk" value=""/>
					<b>显示小标:</b><input type="text" name="tab5Brief" id="tab5Brief" value="${tab5Brief}" maxlength="11" size="50"/><span class="txt-rd">11字內</span><br/>
					<b>商品名称:</b><input type="text" name="tab5Name" id="tab5Name" value="${tab5Name}" maxlength="22" size="50"/><span class="txt-rd">22字內</span><br/>
					<span id="tab5Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>商品6</th>
				<td>
					<b>商品编号</b><input type="text" name="tab6ProdId" id="tab6ProdId" maxlength="8" size="10" value="${tab6ProdId}"/><br/>
					<input type="hidden" id="tab6ProdIsOk" value=""/>
					<b>显示小标:</b><input type="text" name="tab6Brief" id="tab6Brief" value="${tab6Brief}" maxlength="11" size="50"/><span class="txt-rd">11字內</span><br/>
					<b>商品名称:</b><input type="text" name="tab6Name" id="tab6Name" value="${tab6Name}" maxlength="22" size="50"/><span class="txt-rd">22字內</span><br/>
					<span id="tab6Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>商品7</th>
				<td>
					<b>商品编号</b><input type="text" name="tab7ProdId" id="tab7ProdId" maxlength="8" size="10" value="${tab7ProdId}"/><br/>
					<input type="hidden" id="tab7ProdIsOk" value=""/>
					<b>显示小标:</b><input type="text" name="tab7Brief" id="tab7Brief" value="${tab7Brief}" maxlength="11" size="50"/><span class="txt-rd">11字內</span><br/>
					<b>商品名称:</b><input type="text" name="tab7Name" id="tab7Name" value="${tab7Name}" maxlength="22" size="50"/><span class="txt-rd">22字內</span><br/>
					<span id="tab7Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>商品8</th>
				<td>
					<b>商品编号</b><input type="text" name="tab8ProdId" id="tab8ProdId" maxlength="8" size="10" value="${tab8ProdId}"/><br/>
					<input type="hidden" id="tab8ProdIsOk" value=""/>
					<b>显示小标:</b><input type="text" name="tab8Brief" id="tab8Brief" value="${tab8Brief}" maxlength="11" size="50"/><span class="txt-rd">11字內</span><br/>
					<b>商品名称:</b><input type="text" name="tab8Name" id="tab8Name" value="${tab8Name}" maxlength="22" size="50"/><span class="txt-rd">22字內</span><br/>
					<span id="tab8Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			
		<c-rt:if test="${not empty advId}">
			<tr>
				<th>修改记录</th>
				<td>
					<p>建立：<fmt:formatDate value="${createDate}" pattern="yyyy-MM-dd HH:mm"/> / ${createUser}</p>
					<p>修改：<fmt:formatDate value="${modifyDate}" pattern="yyyy-MM-dd HH:mm"/> / ${modifyUser}</p>
				</td>
			</tr>
		</c-rt:if>
			<tr>
				<td colspan="2">
					<input type="hidden" id="advId" name="advId" value="${advId}"/>
					<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/>
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>
<div class="f-link">
	<a href="${midContextPath}/generate/cateMainProd/search.do">回广告查询页</a>
</div>